import Vue from 'vue';
import router from './router';
import store from './store';
import 'vant/lib/index.css';
import App from './App.vue';

// 手动给AutoWeb封装一个promise方法
AutoWeb.autoPromise = function (eventname, params) {
	return new Promise((resolve, reject) => {
		AutoWeb.auto(eventname, params, result => {
			resolve(result);
		});
	});
}

const myApp = new Vue({
	el: '#app',
	router,
	store,
	render: h => h(App),
});
Vue.prototype.$EventBus = new Vue();
window.routeBack = function () {
	if (/^index$/.test(myApp.$route.name)) {
		if (window.routeBackFlag) {
			AutoWeb.auto('exit');
		} else {
			window.routeBackFlag = true;
			AutoWeb.auto('toast', '再按一次退出程序');
			setTimeout(() => {
				window.routeBackFlag = false;
			}, 1000)
		}
	} else {
		myApp.$router.back();
	}
}
